Readme for replication materials:

"Election Cycles and Global Religious Intolerance"

Proceedings of the National Academy of Sciences

Gareth Nellis, University of California San Diego

gnellis@ucsd.edu

Please contact me if you have any queries about the data or code.

December 2022

# Folders

- 00-data/cleaning-code: R/Rmd code files that take raw data (not provided in this package, see below) and produces the analysis dataset. 
- 00-data/cleaned-data: Intermediate cleaned data files and the final analysis dataset (analysis_df.rds).
- 00-data/raw-data: Contains the open-access shapefiles for the world map needed to generate Figure 1 of the main paper, additional files needed for the processing of the World Values Survey, and data on which global region each country belongs to.
- 01-output/tabs-figs-si: Contains Rmd file (tabs-figs-si.rmd) that produces all figures in the main paper and the Supplementary Information pdf (tabs-figs-si.pdf); subfolders contain intermediate objects produced by the analysis code.

# Instructions for outputting all tables and figures based on the analysis dataset

- Open 01-output/tabs-figs-si/tabs-figs-si.rmd in RStudio.
- Click "Knit" to compile to pdf. This will produce the tables and figures for the main text, as well as the Supplementary Information.
- Alternatively, click "Run all code chunks" to produce the results within the R environment.
- To recreate *all* analyses from scratch---i.e. to produce all the intermediate objects in the subfolders---set the switches in lines 113 to 128 of the code to "TRUE."

# Instructions for generating the analysis dataset

- The paper relies on existing data that I am not licensed to recirculate. However, all data used for the analysis is freely and publicly available online. Links to the original data files are given in SI Appendix, Tables S2 and S8. If you have any problems accessing original data files, please contact me and I will be happy to help.
- I have provided all cleaning code that takes the raw data (just described) and converts it into intermediate cleaned data files. Note, to run this cleaning code, you will need to download the data from the original sources yourself first. Then, for all files titled "cleaning-*", simply open in RStudio, set the appropriate working directory for the downloaded raw data, and click "Run all code chunks."
- I have provided all of the intermediate dataframes generated by each of the "cleaning-*" code files. This means that you can immediately run the code that appends and merges the intermediate cleaned datasets. To do this, simply open "00-data/cleaning-code/merging-all.rmd" and click "Run all code chunks."

# R packages

All cleaning and analysis was performed in R. This is the version and system information:

platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          4                           
minor          1.1                         
year           2021                        
month          08                          
day            10                          
svn rev        80725                       
language       R                           
version.string R version 4.1.1 (2021-08-10)
nickname       Kick Things  

The following R packages were employed to clean the data:

janitor_2.1.0    
haven_2.4.3       
labelled_2.9.0   
countrycode_1.3.1 
lubridate_1.8.0  
sf_1.0-7          
rio_0.5.29       
forcats_0.5.1     
stringr_1.4.1
interflex_1.2.6    
dplyr_1.0.9       
purrr_0.3.4      
readr_2.1.2       
tidyr_1.2.0      
tibble_3.1.8      
ggplot2_3.3.6    
tidyverse_1.3.2 

The following R packages were employed to generate the results:

interflex_1.2.6    
scales_1.2.1      
patchwork_1.1.1    
gridExtra_2.3     
ggcorrplot_0.1.3   
fastDummies_1.6.3 
janitor_2.1.0      
modelsummary_0.9.6
knitr_1.40         
ggpubr_0.4.0      
pdftools_3.2.0     
magick_2.7.3      
lfe_2.8-7.1        
Matrix_1.3-4      
cowplot_1.1.1      
dplR_1.7.2        
kableExtra_1.3.4   
broom_0.7.12      
fixest_0.10.3      
haven_2.4.3       
labelled_2.9.0     
countrycode_1.3.1 
lubridate_1.8.0    
sf_1.0-7          
rio_0.5.29         
forcats_0.5.1     
stringr_1.4.1      
dplyr_1.0.9       
purrr_0.3.4        
readr_2.1.2       
tidyr_1.2.0        
tibble_3.1.8      
ggplot2_3.3.6      
tidyverse_1.3.2 